package com.health.userbackstage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.health.userbackstage.pojo.CheckGroup;
import com.health.userbackstage.pojo.CheckItem;
import com.health.userbackstage.pojo.Member;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CheckGroupMapper extends BaseMapper<CheckGroup> {


    @Select("Select * from checkgroup")//需要更改为单表查询，前段页面暂时不用多表联查
//    "SELECT cg.*,ci.`id`  ciid\n" +//多表联查此处不需要
//    "FROM checkgroup_checkitem cc,checkgroup cg,checkitem ci\n" +
//    "WHERE cg.`id`=cc.`checkgroup_id` AND ci.`id`=cc.`checkitem_id`"
    @ResultMap("checkgroupMap")
    List<CheckGroup> findAll();

    @Select("SELECT ci.`id`  ciid\n" +
            "FROM checkgroup_checkitem cc,checkgroup cg,checkitem ci\n" +
            "WHERE cg.`id`=cc.`checkgroup_id` AND ci.`id`=cc.`checkitem_id`")
    List<Integer> findCiid(Integer cgid);

    @Select("select * from checkitem")
    List<CheckItem> findCheckItems();

    @Update("update checkgroup " +"\n"+
            "set code=#{code}," +"\n"+
            "name=#{name}," +"\n"+
            "helpcode=#{helpCode}," +"\n"+
            "sex=#{sex}," +"\n"+
            "remark=#{remark}," +"\n"+
            "attention=#{attention} " +"\n"+
            "where id=#{id}")
    int updateById(CheckGroup checkGroup);

    @Insert("insert into checkGroup values (#{id},#{code},#{name},#{helpCode},#{sex},#{remark},#{attention})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    int insert(CheckGroup checkGroup);

    @Delete("delete from checkGroup where id = #{id}")
    int deleteById(Integer id);

    @Select("select * from checkgroup where code=#{checkGroup.code}")
    CheckGroup selectOneByCode(@Param("checkGroup") CheckGroup checkGroup);

    @Select("select * from checkgroup where name=#{checkGroup.name}")
    CheckGroup selectOneByName(@Param("checkGroup") CheckGroup checkGroup);

    @Select("select * from checkgroup where helpcode=#{checkGroup.helpCode}")
    CheckGroup selectOneByHelpCode(@Param("checkGroup") CheckGroup checkGroup);
}
